package com.hankol.winecellar.adapter

import android.annotation.SuppressLint
import android.net.Uri
import android.widget.FrameLayout
import com.baselibrary.extension.checkValue
import com.baselibrary.extension.load
import com.baselibrary.view.RoundCornerImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.winecellar.R
import com.hankol.winecellar.bean.WineryCoverBean
import java.io.File


/**酒窖详情-横向封面列表
 *@author:hanke
 *2022/3/30
 *desc:
 */
class WineryDetailSubCoverAdapter :
    BaseQuickAdapter<WineryCoverBean, BaseViewHolder>(R.layout.item_winery_sub_cover) {

    override fun convert(helper: BaseViewHolder, item: WineryCoverBean) {
        helper.apply {
//            val tempUrl =if(item.type==0)item.coverUrl else item.videoUrl
            val tempUrl =item.coverUrl
            if ((tempUrl).startsWith("http")) {
                getView<RoundCornerImageView>(R.id.img_cover).load(mContext, tempUrl.checkValue())
            } else {
                Glide.with(mContext).load(Uri.fromFile(File(tempUrl)))
                    .into(getView<RoundCornerImageView>(R.id.img_cover));
            }
            getView<FrameLayout>(R.id.ll_root).setBackgroundResource(if (item.isSelect) R.drawable.bg_stroke_df3_r6 else R.drawable.bg_stroke_white_r6)
            setGone(R.id.img_video_tag, item.type == 1)
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    fun upSelected(selectedPos: Int) {
        for (index in 0 until data.size) {
            data[index].isSelect = selectedPos == index
        }
        notifyDataSetChanged()
    }
}